import json
import os
from typing import Optional, Dict, Any

from app.enmus.task_status_enums import TaskStatus
from app.models.notes_model import NoteResult
from app.utils.logger import get_logger

logger = get_logger(__name__)

NOTE_OUTPUT_DIR = os.getenv("NOTE_OUTPUT_DIR", "note_results")

class TaskDAO:
    def __init__(self):
        pass

    def get_task(self, task_id: str) -> Optional[Dict[str, Any]]:
        """从文件系统获取任务结果"""
        try:
            result_path = os.path.join(NOTE_OUTPUT_DIR, f"{task_id}.json")
            if not os.path.exists(result_path):
                logger.error(f"任务文件不存在: {result_path}")
                return None

            with open(result_path, "r", encoding="utf-8") as f:
                result_content = json.load(f)
                
            return result_content
        except Exception as e:
            logger.error(f"获取任务失败: {e}")
            return None 